<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" prop="date">
        <el-date-picker clearable size="small" v-model="queryParams.date" type="date" value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['Productionline:wushui:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['Productionline:wushui:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['Productionline:wushui:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['Productionline:wushui:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="wushuiList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="主键id" align="center" prop="id" /> -->
      <el-table-column label="日期" align="center" prop="date">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="水泵" align="center" prop="a1">
        <template slot-scope="scope">
          <span>{{scope.row.a1==0?'异常':'正常'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="污水泵" align="center" prop="a2">
        <template slot-scope="scope">
          <span>{{scope.row.a2==0?'异常':'正常'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="污泥泵" align="center" prop="a3">
        <template slot-scope="scope">
          <span>{{scope.row.a3==0?'异常':'正常'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="鼓风机" align="center" prop="a4">
        <template slot-scope="scope">
          <span>{{scope.row.a4==0?'异常':'正常'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="控制柜" align="center" prop="a5">
        <template slot-scope="scope">
          <span>{{scope.row.a5==0?'异常':'正常'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="厌氧池" align="center" prop="a6">
        <template slot-scope="scope">
          <span>{{scope.row.a6==0?'异常':'正常'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="好氧池" align="center" prop="a7">
        <template slot-scope="scope">
          <span>{{scope.row.a7==0?'异常':'正常'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="沉淀池" align="center" prop="a8">
        <template slot-scope="scope">
          <span>{{scope.row.a8==0?'异常':'正常'}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="异常处理描述" align="center" prop="a9" /> -->
      <!-- <el-table-column label="检查人" align="center" prop="a10" /> -->
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <span>{{scope.row.status==0?'审核中':'已审核'}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="备注" align="center" prop="a11" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="240">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['Productionline:wushui:edit']">修改</el-button>
          <el-button size="mini" type="text" v-hasPermi="['Productionline:wushui:approve']" icon="el-icon-circle-check"
            v-show="scope.row.status!=1" @click="handleApprove(scope.row)">审核</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['Productionline:wushui:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改污水处理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body  v-myDialogDrag>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row>
          <el-col :span="12">
            <el-col :span="24">
              <el-form-item label="日期" prop="date">
                <el-date-picker clearable v-model="form.date" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"
                  :disabled="openDisabled">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="污水泵" prop="a2">
                <el-radio-group v-model="form.a2" :disabled="openDisabled">
                  <el-radio label="0">异常</el-radio>
                  <el-radio label="1">正常</el-radio>
                </el-radio-group>

              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="鼓风机" prop="a4">
                <el-radio-group v-model="form.a4" :disabled="openDisabled">
                  <el-radio label="0">异常</el-radio>
                  <el-radio label="1">正常</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="厌氧池" prop="a6">
                <el-radio-group v-model="form.a6" :disabled="openDisabled">
                  <el-radio label="0">异常</el-radio>
                  <el-radio label="1">正常</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="沉淀池" prop="a8">
                <el-radio-group v-model="form.a8" :disabled="openDisabled">
                  <el-radio label="0">异常</el-radio>
                  <el-radio label="1">正常</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="审核人" prop="remark">
                <el-input v-model="form.remark" placeholder="请输入审核人" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="24">
              <el-form-item label="检查人" prop="a10">
                <el-input v-model="form.a10" placeholder="请输入检查人" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="水泵" prop="a1">
                <el-radio-group v-model="form.a1" :disabled="openDisabled">
                  <el-radio label="0">异常</el-radio>
                  <el-radio label="1">正常</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="污泥泵" prop="a3">
                <el-radio-group v-model="form.a3" :disabled="openDisabled">
                  <el-radio label="0">异常</el-radio>
                  <el-radio label="1">正常</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="控制柜" prop="a5">
                <el-radio-group v-model="form.a5" :disabled="openDisabled">
                  <el-radio label="0">异常</el-radio>
                  <el-radio label="1">正常</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="好氧池" prop="a7">
                <el-radio-group v-model="form.a7" :disabled="openDisabled">
                  <el-radio label="0">异常</el-radio>
                  <el-radio label="1">正常</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>


            <el-col :span="24">
              <el-form-item label="异常处理描述" prop="a9">
                <el-input type="textarea" v-model="form.a9" placeholder="请输入异常处理描述" :disabled="openDisabled" />
              </el-form-item>
            </el-col>

          </el-col>

          <!-- <el-col :span="12">
                <el-form-item label="状态">
                  <el-radio-group v-model="form.status" :disabled="openDisabled">
                    <el-radio label="1">请选择字典生成</el-radio>
                  </el-radio-group>
                </el-form-item>
            </el-col> -->
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled||openApprove">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listWushui, getWushui, delWushui, addWushui, updateWushui } from "@/api/quality/productionline/wushui";

  export default {
    name: "Wushui",
    data() {
      return {
        //弹窗是否禁止编辑
        openDisabled: true,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 污水处理表格数据
        wushuiList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          date: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          a1: [
            { required: true, message: '请选择状态', trigger: 'blur' }
          ],
          a2: [
            { required: true, message: '请选择状态', trigger: 'blur' }
          ],
          a3: [
            { required: true, message: '请选择状态', trigger: 'blur' }
          ],
          a4: [
            { required: true, message: '请选择状态', trigger: 'blur' }
          ],
          a5: [
            { required: true, message: '请选择状态', trigger: 'blur' }
          ],
          a6: [
            { required: true, message: '请选择状态', trigger: 'blur' }
          ],
          a7: [
            { required: true, message: '请选择状态', trigger: 'blur' }
          ],
          a8: [
            { required: true, message: '请选择状态', trigger: 'blur' }
          ],
          date: [
            { required: true, message: '请选择日期', trigger: 'blur' }
          ],
        },
        openApprove: false
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询污水处理列表 */
      getList() {
        this.loading = true;
        listWushui(this.queryParams).then(response => {
          this.wushuiList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          date: null,
          a1: '1',
          a2: '1',
          a3: '1',
          a4: '1',
          a5: '1',
          a6: '1',
          a7: '1',
          a8: '1',
          a9: null,
          a10: null,
          a11: null,
          status: "0",
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          delFlag: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.openDisabled = false;
        this.openApprove = false;
        this.open = true;
        this.title = "添加污水处理";
        this.$set(this.form, "a10", this.$store.state.user.nickName)
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.openDisabled = false;
        this.openApprove = false;
        const id = row.id || this.ids
        getWushui(id).then(response => {
          this.form = response.data
          this.open = true;
          this.title = "修改污水处理";
        });
      },
      /** 审核按钮操作 */
      handleApprove(row) {
        this.reset();
        this.openDisabled = true;
        const id = row.id || this.ids
        this.openApprove = true;
        // this.$set(this.form, "remark", this.$store.state.user.nickName)
        // this.$set(this.form, "status", 1)
        getWushui(id).then(response => {
          response.data.status = 1;
          response.data.remark = this.$store.state.user.nickName;
          this.form = response.data
          this.open = true;
          this.title = "审核污水处理";
        });
      },
      /** 查看按钮 */
      handleView(row) {
        this.reset();
        this.openApprove = false;
        this.openDisabled = true;
        const id = row.id || this.ids
        getWushui(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "查看污水处理";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateWushui(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              const rLoading = this.openLoading();
              addWushui(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                rLoading.close();
                this.getList();
              }).catch((error) => {
                rLoading.close();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除该数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delWushui(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => { });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/wushui/export', {
          ...this.queryParams
        }, '污水处理' + this.parseTime(new Date) + '.xlsx')
      }
    }
  };
</script>
